const Service = require('egg').Service;

class GradeService extends Service {
  async index() {
    const { app } = this;

  }

  async addGrade() {
    const { app } = this;
    const { stuid, theory, skill, username, createTime } = this.ctx.request.body;
    const data = await app.mysql.get('users', { stuid })
    if (data) {
      const data = await app.mysql.insert('grade', {
        stuid, theory, skill, username, createTime
      })
      return { code: 0, msg: 'success', data }
    } else {
      return { code: -1, msg: 'fail' }
    }
  }

  async grade() {
    const { app } = this;
    const data = await app.mysql.query(`
     select users.username, theory, skill from users inner join grade on users.stuid = grade.stuid 
    `)
    return { code: 0, msg: 'success', data }
  }

  // async deleteGrade() {
  //   const { app } = this;

  // }
}

module.exports = GradeService;